//
//  LGTHomeCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/3.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTHomeCell: UITableViewCell {

    var userImageView:UIImageView?
    var titleLabel:UILabel?
    var typeLabel:UILabel?
    var reviewLabel:UILabel?
    var earnLabel:UILabel?
    var leastCountLabel:UILabel?
    
    var _model:TaskModel?
    var model:TaskModel?{
        get{
            return _model
        }set{
            _model = newValue
            self.setData()
        }
    }
    
    func setData(){
        self.titleLabel?.text = self.model?.title
        let money:Int = self.model?.price ?? 0
        self.earnLabel?.text = String(format: "赚%.2f", Double(money) / 100.0)
        self.leastCountLabel?.text = "剩余\(self.model?.free_count ?? 0)个名额"

        self.typeLabel?.text = " \(self.model?.type_name ?? "") "
        self.reviewLabel?.text = " \(self.model?.review_time_limit_name ?? "")审核 "
        BaseUtil.baseUtil.setImage(imageView: self.userImageView!, imageUrl: self.model?.user_info?.avatar?.url ?? "")
        //self.typeLabel?.text = self.model.
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        
        self.userImageView = LGTViewCreateUtil.share.createImageViewCorner(corner: SizeFitFloat(23))
         self.userImageView?.backgroundColor = ViewBackColor
        self.addSubview(self.userImageView!)
        self.userImageView?.snp.makeConstraints({ (make) in
            make.width.height.equalTo(SizeFit(46))
            make.left.equalTo(SizeFit(SizeFit(9)))
            //make.centerY.equalTo(self)
            make.top.equalTo(SizeFit(SizeFit(15)))
        })
        
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(15))
       // self.titleLabel?.numberOfLines = 2
        self.addSubview(self.titleLabel!)
        self.titleLabel!.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(SizeFit(57)))
            //make.width.equalTo(KScreenW / 2)
            make.height.equalTo(SizeFit(15))
            make.top.equalTo(SizeFit(15))
        }
        
        //roofplacement
        let hotImage:UIImageView = LGTViewCreateUtil.share.createImageViewCorner(corner: CGFloat(SizeFit(3)), imageName: "")
        hotImage.layer.borderWidth = 1
        hotImage.layer.borderColor = ColorUtil(color:0xF62E00).cgColor
        //hotImage.image = LGTOCBaseUtil.recommendImage()
        //recommendImage
        self.addSubview(hotImage)
        hotImage.snp.makeConstraints { (make) in
            make.left.equalTo(self.titleLabel!.snp_rightMargin).offset(SizeFitFloat(12))
            make.height.equalTo(SizeFit(15))
            make.width.equalTo(SizeFit(28))
            make.centerY.equalTo(self.titleLabel!)
        }
        
        let hotLabel:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: ColorUtil(color:0xF62E00), fontSize: SizeFitFloat(10), text: "推荐")
        hotImage.addSubview(hotLabel)
        hotLabel.snp.makeConstraints { (make) in
            make.center.equalTo(hotImage)
            make.height.equalTo(SizeFit(10))
        }
        
        self.earnLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: ColorUtil(color: 0xF62E00), fontSize: SizeFitFloat(15))
        self.addSubview(self.earnLabel!)
        self.earnLabel!.snp.makeConstraints { (make) in
            make.right.equalTo(SizeFitFloat(-12))
            make.height.equalTo(SizeFitFloat(15))
            make.top.equalTo(SizeFit(15))
            // make.centerY.equalTo(self.userImageView!)
        }
        
        self.typeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: GrayColor, fontSize: SizeFitFloat(10), text: "", corner: SizeFitFloat(3))
        self.typeLabel?.backgroundColor = ColorUtil(color: 0xE5E5E5)
        self.addSubview(self.typeLabel!)
        self.typeLabel!.snp.makeConstraints { (make) in
            make.left.equalTo(self.titleLabel!)
            make.height.equalTo(SizeFit(16))
             make.top.equalTo(SizeFit(46))
            //make.top.equalTo(SizeFit(52))
           // make.top.equalTo(self.titleLabel!.snp_bottomMargin).offset(SizeFit(14))
        }
        
        self.reviewLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: GrayColor, fontSize: SizeFitFloat(10), text: "", corner: SizeFitFloat(3))
        self.reviewLabel?.backgroundColor = ColorUtil(color: 0xE5E5E5)
        self.addSubview(self.reviewLabel!)
        self.reviewLabel!.snp.makeConstraints { (make) in
            make.left.equalTo(self.typeLabel!.snp_rightMargin).offset(SizeFit(15))
            make.height.equalTo(SizeFit(16))
            make.centerY.equalTo(self.typeLabel!)
            //make.top.equalTo(SizeFit(46))
           // make.top.equalTo(self.titleLabel!.snp_bottomMargin).offset(SizeFit(14))
        }
        
        self.leastCountLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.right, textColor: TextColor, fontSize: SizeFitFloat(10))
        self.addSubview(self.leastCountLabel!)
        self.leastCountLabel!.snp.makeConstraints { (make) in
            make.right.equalTo(SizeFitFloat(-12))
            make.height.equalTo(SizeFitFloat(10))
            make.centerY.equalTo(self.typeLabel!)
        }
        
        let line:UIImageView = LGTViewCreateUtil.share.createLineView()
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(9))
            make.right.equalTo(-SizeFit(9))
            make.height.equalTo(1)
            make.top.equalTo(SizeFit(76))
            make.bottom.equalTo(0)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
